// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    remark:'',
    phone:0,
    roleid:0,
    cartList:[],
    sumMoney:0,
    orderNumber:0
  },
  beizhu:function(e){
    this.setData({
      remark:e.detail.value
    })
  },
  beizhu2: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },

  payforit:function(){
    var that = this;
    wx.request({
            url:  'http://localhost:8082/user/wxUpdate', // 仅为示例，并非真实的接口地址
            method:  'post',
            data:  {
              account: wx.getStorageSync('account'),
                  phone :that.data.phone
            },
            header:  {
                'content-type':  'application/x-www-form-urlencoded', // 默认值
                'Authorization':  that.data.token
            },
            success(res)  {
                wx.hideLoading();
                console.info(res.data);
                if  (res.data['msg']  ==  "成功")  {
                    wx.switchTab({
                        url:  '/pages/mine/mine',
                    })
                    wx.showToast({
                        title:  '修改成功',
                        icon:  'true',
                        duration:  1000
                    })
                }  else  {
                    wx.showToast({
                        title:  res.data['msg'],
                        icon:  'none',
                        duration:  2000
                    })
                }
            }
        })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '快点付款吧！'
    })
    var that = this;
    this.setData({
      cartList: wx.getStorageSync('cartList'),
      sumMoney: wx.getStorageSync('sumMoney'),
      orderNumber: wx.getStorageSync('orderNumber'),
      token:wx.getStorageSync('token'),
      account:wx.getStorageSync('account')
    })
    wx.request({
      url: "http://localhost:8082/account/userinfo",
      method: "POST",
      data: {
        account:that.data.account
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        'Authorization': that.data.token
      },
      success: function (res) {
        console.log(res);console.log(that.data.account)
        if (res.statusCode == 200) {
          that.setData({
            phone:res.data.data.phone,
            roleid:res.data.data.roleid
          })
          var json=JSON.stringify(that.data.cartList);
          console.log(json)
          console.log(that.data.remark)
        }else {
          // wx.setStorageSync('jwtMessage', "认证信息已过期，请重新登录");
          wx.reLaunch({
            url: '/pages/openid/openid',
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})